<template>
  <div class="app-container">
      <el-form ref="form" :model="form" disabled label-width="80px">
    <el-tabs type="card">
      <el-tab-pane label="基本信息">
        <el-form-item label="年级" prop="year">
          <el-input v-model="form.year" placeholder="请输入年级" />
        </el-form-item>
        <el-form-item label="专业" prop="specId">
          <el-input v-model="form.specName" />
        </el-form-item>
        <el-form-item label="班级" prop="classId">
          <el-input v-model="form.className" />
        </el-form-item>
        <el-form-item label="学号" prop="code">
          <el-input v-model="form.code" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option v-for="dict in sexOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号" prop="idcard">
          <el-input v-model="form.idcard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="宿舍" prop="roomId">
          <el-input v-model="form.roomName" />
        </el-form-item>
      </el-tab-pane>
      <el-tab-pane label="考试成绩">
        <el-table :data="examResultList">
          <el-table-column label="学期" align="center" prop="semName" />
          <el-table-column label="课程" align="center" prop="courseName" />
          <el-table-column label="教师" align="center" prop="tname" />
          <el-table-column label="平时成绩" align="center" prop="result1"/>
          <el-table-column label="期中成绩" align="center" prop="result2"/>
          <el-table-column label="期末成绩" align="center" prop="result3"/>
          <el-table-column label="实操/实验成绩" align="center" prop="result4"/>
          <el-table-column label="总评成绩" align="center" prop="totalResult" />
          <el-table-column label="补考成绩" align="center" prop="makeupResult" :formatter="makeupFormat"/>
          <el-table-column label="清考成绩" align="center" prop="finalResult" :formatter="finalFormat"/>
          <el-table-column label="成绩级别" align="center" prop="level" :formatter="levelFormat" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="获奖荣誉">
        <el-table :data="gloryList">
          <el-table-column label="获奖名称" align="center" prop="title" />
          <el-table-column label="班级" align="center" prop="className" />
          <el-table-column label="奖项类型" align="center" prop="type" :formatter="gtypeFormat" />
          <el-table-column label="奖项级别" align="center" prop="level" :formatter="glevelFormat" />
          <el-table-column label="颁奖单位" align="center" prop="depart" />
        </el-table>
      </el-tab-pane>
    </el-tabs>
    </el-form>
  </div>
</template>

<script>
  import { getStudent } from "@/api/base/student";
  import { listExamResult} from "@/api/exam/examResult";
  import { selectClazz  } from "@/api/base/clazz";
  import { selectRoom  } from "@/api/base/room";
  import { selectSpecialty } from "@/api/base/specialty";
  import { listStudent } from "@/api/glory/student";


  export default {
    name: "StudentArchive",
    props: {
      studentId: {
        type: Number,
        required: true
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 成绩数据
        examResultList: [],
        //荣耀
        gloryList: [],
        // 房间数据
        roomList: [],
        // 弹出层标题
        title: "",
        // 性别字典
        sexOptions: [],
        // 是否字典
        yesnoOptions: [],
        // 类别字典
        typeOptions: [],
        // 状态字典
        statusOptions: [],
        // 成绩级别字典
        levelOptions: [],
        // 奖项类型字典
        gtypeOptions: [],
        // 奖项级别字典
        glevelOptions: [],
        // 表单参数
        form: {}
      };
    },
    created() {
      this.getDicts("sys_user_sex").then(response => {
        this.sexOptions = response.data;
      });
      this.getDicts("sys_yes_no").then(response => {
        this.yesnoOptions = response.data;
      });
      this.getDicts("student_type").then(response => {
        this.typeOptions = response.data;
      });
      this.getDicts("result_level").then(response => {
        this.levelOptions = response.data;
      });
      this.getDicts("common_status").then(response => {
        this.statusOptions = response.data;
      });
      this.getDicts("glory_type").then(response => {
        this.gtypeOptions = response.data;
      });
      this.getDicts("glory_level").then(response => {
        this.glevelOptions = response.data;
      });

      this.init();
    },
    watch: {
      studentId: {
        deep: true,
        handler() {
          this.init();
        }
      }
    },
    methods: {
      init(){
        if(this.studentId != null){
          this.getStudent();
          this.getResultList();
          this.getGlory();
        }
      },
      getGlory() {
        listStudent({studentId:this.studentId}).then(response => {
          this.gloryList = response.rows;
        });
      },
      /** 查询学生 */
      getStudent() {
        getStudent(this.studentId).then(response => {
          this.form = response.data;
        });
      },
      /** 查询成绩列表 */
      getResultList() {
        listExamResult({studentId:this.studentId}).then(response => {
          this.examResultList = response.rows;
        });
      },
      // 成绩级别字典翻译
      levelFormat(row, column) {
        return this.selectDictLabel(this.levelOptions, row.level);
      },
      makeupFormat(row, column) {
        return this.selectDictLabel(this.levelOptions, row.makeupResult);
      },
      finalFormat(row, column) {
        return this.selectDictLabel(this.levelOptions, row.finalResult);
      },
      // 性别字典翻译
      sexFormat(row, column) {
        return this.selectDictLabel(this.sexOptions, row.sex);
      },
      // 是否住校字典翻译
      isLodgeFormat(row, column) {
        return this.selectDictLabel(this.yesnoOptions, row.isLodge);
      },
      // 类别字典翻译
      typeFormat(row, column) {
        return this.selectDictLabel(this.typeOptions, row.type);
      },
      // 状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 状态字典翻译
      sfdbFormat(row, column) {
        return this.selectDictLabel(this.yesnoOptions, row.sfdb);
      },
      // 奖项类型字典翻译
      gtypeFormat(row, column) {
        return this.selectDictLabel(this.gtypeOptions, row.type);
      },
      // 奖项级别字典翻译
      glevelFormat(row, column) {
        return this.selectDictLabel(this.glevelOptions, row.level);
      },
    }
  };
</script>
